﻿using System;
using System.Windows.Forms;
using DZTC.UselessAppEver.Base32;
using DZTC.UselessAppEver.Core;
using DZTC.UselessAppEver.UI;

namespace DZTC.UselessAppEver

{
    public static class Entry
    {
        private static SelectFilesModel ShowSelectFilesDialog(ApplicationOptions options)
        {
            SelectFilesModel model = null;
            var ct = new SelectFilesController();

            if (options.Mode == ApplicationOptions.ApplicationMode.Default)
            {
                model = ct.ShowDefault();
            }


            if (options.Mode == ApplicationOptions.ApplicationMode.Encode)
            {
                model = ct.ShowEncode(options.FileName);
            }


            if (options.Mode == ApplicationOptions.ApplicationMode.Decode)
            {
                model = ct.ShowDecode(options.FileName);
            }

            return model;
        }

        private static void RunDefaultControlPath(ApplicationOptions options)
        {
            var model = ShowSelectFilesDialog(options);

            if (model == null) return;

            var ct = new ConversionController(model.InputFile, model.OutputFile,
                                              ConversionOperation.CreateConversionOperation(model.Direction));

            ct.RunConversion();
        }

       
        [STAThread]
        public static void Main(params  string[] args)
        {
            Application.EnableVisualStyles();

            var options = ApplicationOptions.Parse(args, Dialog.InvalidOptions);
            if (options == null) return;

            if (options.Mode == ApplicationOptions.ApplicationMode.Install)
            {
                Installer.InstallApplication();
                return;
            }

            if (options.Mode == ApplicationOptions.ApplicationMode.Uninstall)
            {
                Installer.UninstallApplication();
                return;
            }

            RunDefaultControlPath(options);

        }
    }
}
